package com.ruoyi.security.controller;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.security.domain.ScheduleTask;
import com.ruoyi.security.service.IScheduleTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 业务任务Controller
 *
 * @author cjie
 * @date 2022-04-11
 */
@Api(tags = " 业务任务")
@RestController
@RequestMapping("/scheduleTask")
public class InspectionTaskController extends BaseController {
    @Autowired
    private IScheduleTaskService scheduleTaskService;

    /**
     * 查询业务任务列表
     */
    @ApiOperation(value="查询业务任务列表", notes="查询业务任务列表")
    @PreAuthorize(hasPermi = "security:scheduleTask:list")
    @GetMapping("/list")
    public TableDataInfo list(ScheduleTask scheduleTask) {
        startPage();
        List<ScheduleTask> list = scheduleTaskService.selectScheduleTaskList(scheduleTask);
        return getDataTable(list);
    }

    /**
     * 导出业务任务列表
     */
    @ApiOperation(value="导出业务任务列表", notes="导出业务任务列表")
    @PreAuthorize(hasPermi = "security:scheduleTask:export")
    @Log(title = "业务任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ScheduleTask scheduleTask) throws IOException {
        List<ScheduleTask> list = scheduleTaskService.selectScheduleTaskList(scheduleTask);
        ExcelUtil<ScheduleTask> util = new ExcelUtil<ScheduleTask>(ScheduleTask.class);
        util.exportExcel(response, list, "业务任务数据");
    }
    /**
     * 获取业务任务详细信息
     */
    @ApiOperation(value="获取业务任务详细信息", notes="获取业务任务详细信息")
    @PreAuthorize(hasPermi = "security:scheduleTask:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(scheduleTaskService.selectScheduleTaskById(id));
    }

    /**
     * 新增业务任务
     */
    @ApiOperation(value="新增业务任务", notes="新增业务任务")
    @PreAuthorize(hasPermi = "security:scheduleTask:add")
    @Log(title = "业务任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ScheduleTask scheduleTask) {
        return toAjax(scheduleTaskService.insertScheduleTask(scheduleTask));
    }

    /**
     * 新增业务任务
     */
    @ApiOperation(value="远程接口新增业务任务", notes="远程接口新增业务任务")
    @Log(title = "远程接口新增业务任务", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public R addScheduleTask(@RequestBody ScheduleTask scheduleTask) {
        return R.ok(scheduleTaskService.insertScheduleTask(scheduleTask));
    }

    /**
     * 修改业务任务
     */
    @ApiOperation(value="修改业务任务", notes="修改业务任务")
    @PreAuthorize(hasPermi = "security:scheduleTask:edit")
    @Log(title = "业务任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ScheduleTask scheduleTask) {
        return toAjax(scheduleTaskService.updateScheduleTask(scheduleTask));
    }

    /**
     * 删除业务任务
     */
    @ApiOperation(value="删除业务任务", notes="删除业务任务")
    @ApiImplicitParam(name = "ids", value = "业务任务ID数组", required = true,paramType = "path", allowMultiple=true, dataType = "String")
    @PreAuthorize(hasPermi = "security:scheduleTask:remove")
    @Log(title = "业务任务", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(scheduleTaskService.deleteScheduleTaskByIds(ids));
    }
}
